<?php
header("content-type:text/html;charset=utf-8");
$username = $_POST["username"];
$pwd = $_POST["pwd"];

//造对象
$db = new mysqli("localhost", "root", "", "xhm");
//判断是否出错
!mysqli_connect_error() or die("连接失败！");
//sql语句
$sql = "select password from user where userName='$username'";
//执行sql
$result = $db->query($sql);
if ($result) {
    $v = $result->fetch_row();
     //mysql_fetch_row() 函数从结果集中取得一行作为数字数组
    if ($pwd == $v[0]) {
        echo "true";
        header("location:index.php");
    } else {
        echo "登录失败";
    }
} else {
    echo "查询出错!";
}

$db->close();
?>